home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Plotting / aa_Intel_Only / Gnuplot / GnuplotSource / GeneralPane.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  10.2 KB  |  449 lines

  1. /*
  2.  *  Copyright (C) 1993  Robert Davis
  3.  *
  4.  *  This program is free software; you can redistribute it and/or
  5.  *  modify it under the terms of Version 2, or any later version, of 
  6.  *  the GNU General Public License as published by the Free Software 
  7.  *  Foundation.
  8.  */
  9.  
  10.  
  11. static char RCSId[]="$Id: GeneralPane.m,v 1.9 1993/05/18 03:55:06 davis Exp $";
  12.  
  13.  
  14. #import <appkit/Application.h>
  15. #import <appkit/Box.h>
  16. #import <appkit/Button.h>
  17. #import <appkit/Matrix.h>
  18. #import <appkit/Panel.h>        /* NXRunAlertPanel()        */
  19. #import <appkit/Slider.h>
  20. #import <appkit/Text.h>            /* GeneralPane is a text delegate */
  21. #import <appkit/TextField.h>
  22. #import <appkit/TextFieldCell.h>
  23. #import <appkit/View.h>
  24.  
  25. #import <objc/NXStringTable.h>
  26.  
  27. #import "GeneralPane.h"
  28. #import "Status.h"
  29.  
  30.  
  31. @interface GeneralPane (Private)
  32.  
  33. - _updateKeyIsThreeD:(BOOL)isThreeD;
  34. - _updateSize;
  35. - _updateTime;
  36.  
  37. @end
  38.  
  39.  
  40. @implementation GeneralPane
  41.  
  42.  
  43. - init
  44. {
  45.     [super init];
  46.  
  47.     [NXApp loadNibSection: "GeneralPane.nib"
  48.             owner: self
  49.         withNames: NO
  50.          fromZone: [self zone]];
  51.  
  52.     icon = "InspectorGeneral.tiff";
  53.     return self;
  54. }
  55.  
  56.  
  57. /*  
  58.  *  The following methods should be overridden by subclasses.
  59.  */
  60. - selectControl:sender
  61. {
  62.     [titleField selectText:self];
  63.     return self;
  64. }
  65.  
  66.  
  67. - (BOOL)updateStatus:aStatus doc:aDoc
  68. {
  69.     id oldStatus = status;
  70.  
  71.     /*  
  72.      *  We only bother updating if status has changed since we last 
  73.      *  updated, or if we just became the current pane (didSwap) -- 
  74.      *  assuming that status and aDoc are non-nil, of course.
  75.      */
  76.  
  77.     if ([super updateStatus:aStatus doc:aDoc]
  78.     && ((status != oldStatus) || didSwap)) {
  79.  
  80.     BOOL isThreeD = [status isThreeD];
  81.     BOOL isPolar = [status isPolar];
  82.     Window *viewWindow;
  83.     id anId;
  84.  
  85.     [(viewWindow = [view window]) disableDisplay];
  86.  
  87.         [polarButton setState:isPolar];
  88.         [polarButton setEnabled:!isThreeD];
  89.         [parametricButton setState:[status parametric]];
  90.         [borderButton setState:[status border]];
  91.         [self _updateKeyIsThreeD:isThreeD];
  92.         [self _updateTime];
  93.         [[samplesMatrix findCellWithTag:X_TAG] setIntValue:
  94.                         [status samples:X_TAG]];
  95.     anId = [samplesMatrix findCellWithTag:Y_TAG];
  96.         [anId setIntValue:[status samples:Y_TAG]];
  97.     [anId setEnabled:isThreeD];
  98.  
  99.         [self _updateSize];
  100.         [titleField setStringValue:[status title]];
  101.  
  102.     [viewWindow reenableDisplay];
  103.  
  104.     [self perform:@selector(selectControl:)
  105.          with:self
  106.        afterDelay:1
  107.        cancelPrevious:YES];
  108.  
  109.     didSwap = NO;
  110.     return YES;
  111.     }
  112.  
  113.     return NO;
  114. }
  115.  
  116.  
  117. - didSwapIn:sender
  118. {
  119.     didSwap = YES;
  120.     return self;
  121. }
  122.  
  123.  
  124.  
  125. - doSetPlotTitle:sender
  126. {
  127.     [status setTitle: [sender stringValue]];
  128.     [sender setStringValue:[status title]];   /* status may have fixed title */
  129.  
  130.     return self;
  131. }
  132.  
  133.  
  134. - doSetSizeProp:sender
  135. {
  136.     float aValue;
  137.  
  138.     if ([sender state])  {
  139.  
  140.         [status setSizeProp: 1];
  141.  
  142.         [status setSizeX:0
  143.           Y: aValue = [[sizeTextMatrix findCellWithTag:X_TAG] floatValue]];
  144.         [sizeYSlider setFloatValue:aValue];
  145.         [[sizeTextMatrix findCellWithTag:Y_TAG] setFloatValue:aValue];
  146.  
  147.     } else
  148.         [status setSizeProp: 0];
  149.  
  150.     return self;
  151. }
  152.  
  153.  
  154. - doSetSize:sender
  155. {
  156.     float val[((X_TAG > Y_TAG)? X_TAG : Y_TAG) + 1];
  157.     int tag;
  158.     Cell *cell = [sender selectedCell];
  159.  
  160.     val[tag = [sender selectedTag]] = [cell floatValue];
  161.     if ([sizeButton state])
  162.     val[(X_TAG == tag)? Y_TAG : X_TAG] = val[tag];
  163.     else
  164.     val[(X_TAG == tag)? Y_TAG : X_TAG] = 0.0;
  165.  
  166.     [status setSizeX:val[X_TAG] Y:val[Y_TAG]];
  167.     [self _updateSize];
  168.  
  169.     return self;
  170. }
  171.  
  172.  
  173. - doSetBorder:sender
  174. {
  175.     return [status setBorder:[sender state]];
  176. }
  177.  
  178.  
  179. - doSetPolar:sender
  180. {
  181.     [status setPolar:[sender state]];
  182.     if ([self forceUpdateStatus:status doc:doc])
  183.     [view display];
  184.     return self;
  185. }
  186.  
  187.  
  188.  
  189.  
  190. /*  
  191.  *  This method informs the user the first time it is sent that 
  192.  *  parametric plots have special requirements.
  193.  */
  194. - doSetParametric:sender
  195. {
  196.     static BOOL didInform = NO;
  197.     int state = [sender state];
  198.  
  199.     if (!didInform && state) {
  200.         didInform = YES;
  201.         NXRunAlertPanel ([stringSet valueForStringKey: "parametric"],
  202.                          [stringSet valueForStringKey: "needEvenFunctions"],
  203.                          NULL, NULL, NULL);
  204.     }   
  205.     
  206.     return [status setParametric:state];
  207. }
  208.  
  209.  
  210. - doSetSamples:sender
  211. {
  212.     int samples = [sender intValue];
  213.     if (samples > 1)
  214.     [status setSamplesCoord:[sender selectedTag] to:samples];
  215.     else
  216.     [sender setIntValue:[status samples:[sender selectedTag]]];
  217.  
  218.     return self;
  219. }
  220.  
  221.  
  222. - doSetKey:sender
  223. {
  224.     [status setKey: [sender state]];
  225.     [self _updateKeyIsThreeD:[status isThreeD]];
  226.     if (![keyDefaultButton state])
  227.     [keyMatrix selectCellWithTag:X_TAG];
  228.  
  229.     return self;
  230. }
  231.  
  232.  
  233. - doSetKeyLocation:sender
  234. {
  235.     id cell = [sender selectedCell];
  236.     int tag = [cell tag];
  237.     double val = [cell doubleValue];
  238.  
  239.     if ([status isLogCoord:tag] && (val <= 0))  {
  240.         NXRunAlertPanel ([stringSet valueForStringKey: "key"],
  241.                          [stringSet valueForStringKey: "logKey"],
  242.                          NULL, NULL, NULL);
  243.         [self _updateKeyIsThreeD:[status isThreeD]];
  244.     } else
  245.         [status setKeyCoord:tag to:val];
  246.  
  247.     return self;
  248. }
  249.  
  250.  
  251. - doSetKeyDefault:sender
  252. {
  253.     int i;
  254.     BOOL ok = YES;
  255.     BOOL isDefaultOn = [sender state];
  256.  
  257.     for (i = 0 ; i < 3 ; i++)
  258.         if ([status isLogCoord:i] && ([[keyMatrix findCellWithTag:i]
  259.                                                 doubleValue] <= 0)) {
  260.             NXRunAlertPanel ([stringSet valueForStringKey: "key"],
  261.                              [stringSet valueForStringKey: "logKey"],
  262.                              NULL, NULL, NULL);
  263.             ok = NO;
  264.             break;
  265.         }
  266.  
  267.     if (ok)
  268.         [status setKeyDefault: isDefaultOn];
  269.  
  270.     [self _updateKeyIsThreeD:[status isThreeD]];
  271.  
  272.     if (ok && !isDefaultOn)
  273.     [keyMatrix selectCellWithTag:X_TAG];
  274.  
  275.     return self;
  276. }
  277.  
  278.  
  279. - doSetTime:sender
  280. {
  281.     [status setTime: [sender state]];
  282.     [self _updateTime];
  283.  
  284.     if (![timeDefaultButton state])
  285.     [timeMatrix selectCellWithTag:X_TAG];
  286.  
  287.     return self;
  288. }
  289.  
  290.  
  291. - doSetTimeLocation:sender
  292. {
  293.     id cell = [sender selectedCell];
  294.     int tag = [cell tag];
  295.     int val = [cell intValue];
  296.  
  297.     if ([status isLogCoord:tag] && (val <= 0))  {
  298.         NXRunAlertPanel ([stringSet valueForStringKey: "time"],
  299.                          [stringSet valueForStringKey: "logTime"],
  300.                          NULL, NULL, NULL);
  301.         [self _updateTime];
  302.     } else
  303.         [status setTimeCoord:tag to:val];
  304.  
  305.     return self;
  306. }
  307.  
  308.  
  309. - doSetTimeDefault:sender
  310. {
  311.     int i;
  312.     BOOL ok = YES;
  313.     BOOL isDefaultOn = [sender state];
  314.  
  315.     for (i = 0 ; i < 2 ; i++)
  316.         if ([status isLogCoord:i] && ([[timeMatrix findCellWithTag:i]
  317.                                                 doubleValue] <= 0)) {
  318.             NXRunAlertPanel ([stringSet valueForStringKey: "time"],
  319.                              [stringSet valueForStringKey: "logTime"],
  320.                              NULL, NULL, NULL);
  321.             ok = NO;
  322.             break;
  323.         }
  324.  
  325.     if (ok)
  326.         [status setTimeDefault: isDefaultOn];
  327.  
  328.     [self _updateTime];
  329.  
  330.     if (ok && !isDefaultOn)
  331.     [timeMatrix selectCellWithTag:X_TAG];
  332.  
  333.     return self;
  334. }
  335.  
  336.  
  337.  
  338. // Shuts up the compiler about unused RCSId
  339. - (const char *) rcsid
  340. {
  341.     return RCSId;
  342. }
  343.  
  344.  
  345. @end
  346.  
  347.  
  348. @implementation GeneralPane (Private)
  349.  
  350.  
  351. - _updateKeyIsThreeD:(BOOL)isThreeD
  352. {
  353.     int keyState = [status key];
  354.     int keyDefaultState = [status keyDefault];
  355.     int i;
  356.  
  357.     for (i = 0 ; i <= 2 ; i++)
  358.         [[keyMatrix findCellWithTag:i] setDoubleValue:[status keyCoord:i]];
  359.  
  360.     [keyButton setState: keyState];
  361.     [keyDefaultButton setState: keyDefaultState];
  362.     [keyDefaultButton setEnabled: keyState];
  363.  
  364.     if (keyState) {                     /* There is a key...            */
  365.  
  366.         [[keyMatrix findCellWithTag:X_TAG] setEnabled:!keyDefaultState];
  367.     [[keyLabelMatrix findCellWithTag:X_TAG] 
  368.                  setTextGray:keyDefaultState? NX_DKGRAY: NX_BLACK];
  369.  
  370.         [[keyMatrix findCellWithTag:Y_TAG] setEnabled:!keyDefaultState];
  371.     [[keyLabelMatrix findCellWithTag:Y_TAG] 
  372.                  setTextGray:keyDefaultState? NX_DKGRAY: NX_BLACK];
  373.  
  374.         [[keyMatrix findCellWithTag:Z_TAG] setEnabled:!keyDefaultState
  375.                                                       && isThreeD];
  376.     [[keyLabelMatrix findCellWithTag:Z_TAG] 
  377.           setTextGray:(keyDefaultState || !isThreeD)? NX_DKGRAY: NX_BLACK];
  378.  
  379.  
  380.     } else                            /* There is no key              */
  381.         for (i = 0 ; i < 3 ; i++)  {
  382.             [[keyMatrix findCellWithTag:i] setEnabled:NO];
  383.         [[keyLabelMatrix findCellWithTag:i] setTextGray:NX_DKGRAY];
  384.     }
  385.  
  386.     return self;
  387. }
  388.  
  389.  
  390.  
  391. - _updateSize
  392. {
  393.     float value;
  394.  
  395.     [sizeXSlider setFloatValue:value = [status sizeX]];
  396.     [[sizeTextMatrix findCellWithTag:X_TAG] setFloatValue:value];
  397.     if ([status sizeProp])  {
  398.         [sizeYSlider setFloatValue:value = [status sizeY]];
  399.         [[sizeTextMatrix findCellWithTag:Y_TAG] setFloatValue:value];
  400.         [sizeButton setState:1];
  401.     } else {
  402.         [sizeYSlider setFloatValue:value = [status sizeY]];
  403.         [[sizeTextMatrix findCellWithTag:Y_TAG] setFloatValue:value];
  404.         [sizeButton setState:0];
  405.     }
  406.  
  407.     return self;
  408. }
  409.  
  410.  
  411.  
  412.  
  413. - _updateTime
  414. {
  415.     int timeState = [status time];
  416.     int timeDefaultState = [status timeDefault];
  417.  
  418.     [[timeMatrix findCellWithTag:X_TAG] setIntValue: [status timeCoord:X_TAG]];
  419.     [[timeMatrix findCellWithTag:Y_TAG] setIntValue: [status timeCoord:Y_TAG]];
  420.  
  421.     [timeButton setState: timeState];
  422.     [timeDefaultButton setState: timeDefaultState];
  423.     [timeDefaultButton setEnabled: timeState];
  424.  
  425.     if (timeState) {                    /* We do want to show time/date */
  426.  
  427.         [[timeMatrix findCellWithTag:X_TAG] setEnabled:!timeDefaultState];
  428.     [[timeLabelMatrix findCellWithTag:X_TAG]
  429.             setTextGray: timeDefaultState? NX_DKGRAY: NX_BLACK];
  430.         [[timeMatrix findCellWithTag:Y_TAG] setEnabled:!timeDefaultState];
  431.     [[timeLabelMatrix findCellWithTag:Y_TAG]
  432.             setTextGray: timeDefaultState? NX_DKGRAY: NX_BLACK];
  433.  
  434.     } else {                            /* We don't want to show time   */
  435.  
  436.         [[timeMatrix findCellWithTag:X_TAG] setEnabled:NO];
  437.     [[timeLabelMatrix findCellWithTag:X_TAG] setTextGray: NX_DKGRAY];
  438.         [[timeMatrix findCellWithTag:Y_TAG] setEnabled:NO];
  439.     [[timeLabelMatrix findCellWithTag:Y_TAG] setTextGray: NX_DKGRAY];
  440.  
  441.     }
  442.     return self;
  443. }
  444.  
  445.  
  446.  
  447.  
  448. @end
  449.